package jse;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.NumberFormat;

public class Test {  
    public static void main(String[] args) {  
        String str="0.2";  
        double d= Double.parseDouble(str);
        BigDecimal bd = new BigDecimal(d);  
        System.out.println(bd.setScale(2, BigDecimal.ROUND_HALF_UP).toString());  
        System.out.println("=================");  
         DecimalFormat df = new DecimalFormat("#.00");   
         System.out.println(df.format(0.256));   
         System.out.println("=================");  
         System.out.println(String.format("%.2f", Double.parseDouble(str)));  
         System.out.println("=================");  
         NumberFormat nf = NumberFormat.getNumberInstance();   
         nf.setMaximumFractionDigits(2);   
         System.out.println(nf.format(Double.parseDouble(str)));   
    }  
}  